﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Wassrile.Dialogs
{
    public partial class AccountReq : Form
    {
        public AccountReq()
        {
            InitializeComponent();
        }

        public string UserId { get; private set; }

        public bool UseToken { get; private set; }

        public string Password { get; private set; }

        private void requestToken_Click(object sender, EventArgs e)
        {
            using (var tokenAuth = new TokenAuth())
            {
                if (tokenAuth.ShowDialog() == DialogResult.OK)
                {
                    tokenPassword.Text = tokenAuth.Token;
                    OKBtnValidation(sender, e);
                }
            }
        }

        private void useToken_CheckedChanged(object sender, EventArgs e)
        {
            basicPassword.Enabled = !useToken.Checked;
            requestToken.Enabled = useToken.Checked;
            tokenPassword.Enabled = useToken.Checked;
            OKBtnValidation(sender, e);
        }

        private void wassrLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Krile.Kernel.Bridge.CommonOperation.CallBrowser("http://wassr.jp/");
        }

        private void OKBtn_Click(object sender, EventArgs e)
        {
            UserId = userId.Text;
            UseToken = useToken.Checked;
            Password = useToken.Checked ? tokenPassword.Text : basicPassword.Text;
        }

        private void OKBtnValidation(object sender, EventArgs e)
        {
            OKBtn.Enabled =
                (userId.Text != string.Empty) &&
                ((useToken.Checked && tokenPassword.Text != String.Empty) ||
                (useBasic.Checked && basicPassword.Text != String.Empty));

        }
    }
}
